/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including but not limited to the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to provide persons with access to the Software
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGE OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

<template>
  <div>
    <div class="tab-container">
      <img
        class="back-icon"
        src="../../assets/videoList/images/backIcon.png"
        @click="goBack"
      />
      <div class="tab-bar">
        <div class="tab-scroll">
          <div
            v-for="(tab, index) in tabs"
            :key="tab.id"
            class="tab-button"
            :class="{ 'active-tab': activeTab === index }"
            @click="setActiveTab(index)"
          >
            <span
              class="tab-text"
              :class="{ 'active-tab-text': activeTab === index }"
            >
              {{ tab.title }}
            </span>
          </div>
        </div>
      </div>
      <div :class="['tab-more']">
        <div class="tab-search" v-show="isLandscape">
          <img
            class="tab-search-img"
            src="../../assets/videoList/images/lg-search.png"
          />
          <input class="tab-search-input" placeholder="搜索..." />
        </div>
        <img
          class="tab-more-img"
          v-show="isLandscape"
          src="../../assets/videoList/images/history.png"
        />
        <img
          class="tab-more-img"
          src="../../assets/videoList/images/rightMore.png"
        />
      </div>
    </div>
    <div :class="['tab-more', 'tab-moreMobile']" v-show="!isLandscape">
      <div class="tab-search">
        <img
          class="tab-search-img"
          src="../../assets/videoList/images/lg-search.png"
        />
        <input class="tab-search-input" placeholder="搜索..." />
      </div>
      <img
        class="tab-more-img"
        src="../../assets/videoList/images/history.png"
      />
    </div>
  </div>
</template>

<script>
import { BreakpointManager } from '@hadss/web_adaptive_layout_ui';

export default {
  data() {
    return {
      activeTab: 0,
      breakpointManager: new BreakpointManager(),
      deviceType: 'mobile',
      isLandscape: false,
      unsubscribe: null,
      tabs: [
        { id: '00', title: '精选' },
        { id: '01', title: '视频' },
        { id: '02', title: '社区' },
        { id: '03', title: '新闻' },
        { id: '04', title: '购物' },
        { id: '05', title: '科技' },
        { id: '06', title: '财经' },
        { id: '07', title: '历史' },
        { id: '08', title: '军事' },
      ],
    };
  },
  mounted() {
    this.unsubscribe = this.breakpointManager.subscribeToBreakpoint(() => {
      this.isLandscape = this.breakpointManager.useBreakpointValue({
        sm: false,
        md: true,
      });
    });
  },
  beforeDestroy() {
    if (this.unsubscribe) {
      this.unsubscribe();
    }
  },
  methods: {
    setActiveTab(index) {
      this.activeTab = index;
    },
    goBack() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped>
.tab-container {
  display: flex;
  width: 100%;
  height: 56px;
  align-items: center;
}

.tab-bar {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
  display: none;
}

.back-icon {
  width: 40px;
  height: 40px;
  padding-right: 10px;
}

.tab-scroll {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.tab-more {
  display: flex;
  align-items: center;
  padding-left: 8px;
  margin-right: 0;
}

.tab-more-img {
  width: 40px;
  height: 40px;
  padding-right: 8px;
}

.tab-more-img:last-child {
  padding-right: 0;
}

.tab-search {
  width: 100%;
  min-width: 138px;
  height: 40px;
  line-height: 40px;
  border-radius: 20px;
  background-color: rgba(241, 243, 245, 0.8);
  padding-right: 12px;
  padding-left: 12px;
  margin-right: 12px;
  text-align: start;
}

.tab-search-img {
  width: 12px;
  height: 12px;
}

.tab-search-input {
  all: unset;
  padding-left: 12px;
}

.tab-moreMobile {
  padding: 8px 0 8px 0;
}

.tab-button {
  width: 60px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 40px;
  margin-right: 8px;
  background-color: rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: background-color 0.3s;
}

.tab-button.active-tab {
  background-color: #0a59f7;
}

.tab-text {
  font-size: 16px;
  line-height: 40px;
  color: #000;
  text-align: center;
}

.tab-text.active-tab-text {
  color: #fff;
}

.tab-more-tablet {
  width: 50%;
}
</style>
